#include <iostream>
#include <string>
#include <cstring>
#include <signal.h>
#include <unistd.h>
#include "KcpSender.h"

using namespace std;
bool bquit = false;

long long getTimeStampMil()
{
    struct timespec ts;
    if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) {
        return 1;
    }
    long long ms = ts.tv_nsec / 1000000 + ts.tv_sec * 1000;
    return ms;
}

void sig_handler(int signo) {
    if (signo == SIGINT) {
        bquit = true;
    }
}

int main() {
    KCPSender* send = new KCPSender();
    signal(SIGINT, sig_handler);
    char data[1024];
    send->InitSender("127.0.0.1", 10000, "127.0.0.1", 20000);
    long long start = getTimeStampMil();
    int packet_count = 10000;
    while (!bquit) {
        send->SendData(data, 1024);
        usleep(2* 1000);
        if (packet_count-- == 0) {
            long long end = getTimeStampMil();
            cout << "time cost: " << (end - start) << endl;
            bquit = true;
        }
    }
    send->Close();
    delete send;
    return 0;
}